﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="PageACLAdd.aspx.cs" Inherits="ProjectStudy.PageACLManage.PageACLAdd" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="../Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
    <script src="../Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script src="../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            $.ajax({
                type: "post",
                url: "../Ajax/Menu_Manage.ashx",
                data: { "action": "GetGroupList" },
                dataType: "json",
                success: function (data) {
                    if (data != null && data != '') {
                        $.each(data, function (index, item) {
                            $("#selgroup").append('<option id="' + 'op' + (index + 1) + '"' + ' value="' + item.class + '">' + item.GroupName + '</option>');
                        });
                        $("#tbGroup").val($("#selgroup").val());
                    }
                    else {
                        $("#selgroup").append('<option id="' + 'op' + '0' + '"' + ' value="' + '-1' + '">' + '无用户组' + '</option>');
                    }
                }
            });

            $("#selgroup").change(function () {
                $("#tbGroup").val($("#selgroup").val());
            });

            $("#btnAdd").click(function () {
                FnPageACLAdd();
            });

            $("#btnCancel").click(function () {
                if (confirm("确认返回？")) {
                    window.history.back("PageACLManage.aspx");
                }
            });
        });

        function FnPageACLAdd() {

            var pageid = $.trim($("#tbPageId").val());
            var url = $.trim($("#tbPageUrl").val());
            var group = $.trim($("#selgroup").find("option:selected").text());
            var rightclass = $("#selgroup").val();

            if (pageid.length > 0 && url.length > 0) {
                $.ajax({
                    type: "post",
                    url: "/Ajax/Ajax_PageACLManage.ashx",
                    data: { "action": "AddPageACL", "pageId": pageid, "Url": url, "Group": group, "RightClass": rightclass },
                    dataType: "json",
                    success: function (data) {
                        if (data["status"] == "success") {
                            if (confirm("添加成功，是否返回管理页面？")) {
                                window.history.back("PageACLManage.aspx");
                            }
                        }
                        else if (data["status"] == "insertduplicate") {
                            alert("页面ID已存在");
                        }
                        else if (data["status"] == "insertErr") {
                            alert("添加失败");
                        }
                    }
                });
            }
            else {
                alert("所有*为必填项");
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <table id="tb1">
      <tr>
        <td><label>页面ID</label></td>
        <td><input  type="text" id="tbPageId" placeholder="页面标识符" style=" height:30px; line-height:30px; font-size:16px; width:450px;"/></td>
        <td><label style=" color:Red">*</label></td>
      </tr>
      <tr>
        <td><label>页面URL</label></td>
        <td><input  type="text" id="tbPageUrl" placeholder="页面地址" style=" height:30px; line-height:30px; font-size:14px; width:450px;"/></td>
        <td><label style=" color:Red">*</label></td>
      </tr>
      <tr>
        <td><label>所属用户组</label></td>
        <td><select id="selgroup" style=" height:30px; line-height:30px; font-size:16px;"></select></td>
      </tr>
      <tr>
        <td><label>权限等级</label></td>
        <td><input  type="text" id="tbGroup" disabled="disabled" style=" height:30px; line-height:30px; font-size:16px;"/></td>
      </tr>
      <tr>
        <td></td>
        <td>
        <input  type="button" id="btnAdd" value="添加" style=" height:30px; line-height:30px; font-size:16px;"/>
        <input  type="button" id="btnCancel" value="取消" style=" height:30px; line-height:30px; font-size:16px;"/>
        </td>
      </tr>
    </table>
    
    </div>
    </form>
</body>
</html>
